package com.fwmagic.dp._7._7_1;

import java.util.Random;

public class Main {
    private static int MAX_COUNT = 6;
    public static void main(String[] args) {
        int i =0;
        Mail mail = new Mail(new AdvTemplate());
        mail.setTail("XXX银行版权所有");
        while (i<MAX_COUNT){
            Mail cloneMail = mail.clone();
            cloneMail.setApplication(getRandomString(5) +" 先生（女士）");
            cloneMail.setReceiver(getRandomString(5)+"@"+getRandomString(8));
            //然后发送邮件
            sendMail(cloneMail);
            i++;
        }
    }

    //发送邮件
    private static void sendMail(Mail mail) {
        System.out.println("标题："+mail.getSubject()+"\t 收件人："+mail.getReceiver()+"\t 发送成功！");
    }

    //获得指定长度的随机字符串
    private static String getRandomString(int maxLength) {
        String source = "jeiijjnjwbwhiqbbcdjsaqbfweiwgegeghhh";
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        for(int i=0;i<maxLength;i++){
            sb.append(source.charAt(rand.nextInt(source.length())));
        }
        return sb.toString();
    }
}
